package fem2;

import inf.jlinalg.IVector;
import inf.jlinalg.MatrixFormat;
import junit.framework.Assert;
import math2.MathUtilities;
import math2.MutableDouble;

import org.junit.Test;

import fem2.enu.VariableName;

public class VariableTest {

	@Test
	public void testRegister() {
		Variable var = new Variable(3);
		var.registerScalarVariable(VariableName.ALPHA, true);
		MutableDouble v = var.getScalarVariable(VariableName.ALPHA);
		v.setValue(1.0);
		Assert.assertEquals(1.0, v.getValue(), MathUtilities.tol14);

		var.save();
		v.setValue(2.0);
		var.save();
		v.setValue(3.0);
		var.save();
		v.setValue(4.0);
		var.save();

		System.out.println(var.getScalarVariable(VariableName.ALPHA, 0));
		System.out.println(var.getScalarVariable(VariableName.ALPHA, -1));
		System.out.println(var.getScalarVariable(VariableName.ALPHA, -2));
		System.out.println(var.getScalarVariable(VariableName.ALPHA, -3));
	}

	@Test
	public void testRegister2() {
		Variable var = new Variable(2);
		var.registerVectorVariable(VariableName.BETA, 2, true);
		IVector v = var.getVectorVariable(VariableName.BETA);
		System.out.println(MatrixFormat.format(v));

		v.set(0, 1.0);
		v.set(1, 2.0);
		var.save();
		var.save();

		System.out.println(MatrixFormat.format(var.getVectorVariable(VariableName.BETA, 0)));
		System.out.println(MatrixFormat.format(var.getVectorVariable(VariableName.BETA, -1)));
		System.out.println(MatrixFormat.format(var.getVectorVariable(VariableName.BETA, -2)));
	}
}
